﻿using Furion.DependencyInjection;
using Photo.Entity.System;
using Photo.Respository;

namespace Photo.Application.Core.Service.Dict
{
    /// <summary>
    /// 枚举公共核心服务
    /// </summary>
    public class DictCoreService: ITransient
    {
        private readonly IRepository<SysDictEntity> _sysDictRepository;
        public DictCoreService(IRepository<SysDictEntity> sysDictRepository)
        {
            _sysDictRepository = sysDictRepository;
        }

        /// <summary>
        /// 获取字典名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<string> GetDictName(string id)
        {
            var result = "";
            if (!string.IsNullOrWhiteSpace(id))
            {
                var pEntity = await _sysDictRepository.GetAsync(id);
                if (pEntity != null)
                {
                    if (!string.IsNullOrWhiteSpace(pEntity.PId))
                    {
                        pEntity.Value = ">" + pEntity.Value;
                    }
                    result = await GetDictName(pEntity.PId) + pEntity.Value;
                }
            }

            return result;
        }

    }
}
